package org.ielts.repository;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.ielts.domain.log.SchoolLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.yifeng.dao.HibernateRepository;

@Repository
public class SchoolLogRepository extends HibernateRepository<SchoolLog, String> {

	public Iterable<SchoolLog> findByStudent(String studentId) {
		DetachedCriteria criteria = createDetachedCriteria();
		criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).addOrder(Order.desc("createTime"))
				.createCriteria("student").add(Restrictions.eq("id", studentId));

		@SuppressWarnings("unchecked")
		Iterable<SchoolLog> schoolLogs = hibernateTemplate.findByCriteria(criteria);

		return schoolLogs;
	}
}
